<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href='<?php echo base_url()?>'>
<link rel="stylesheet" type="text/css" href="public/common/css/common.css"/>
<link rel="stylesheet" type="text/css" href="public/admin/css/admin.css"/>
<style>
	.table tr td{border-bottom:1px dashed #ccc;line-height:30px;}
	.table tr td .explode{padding:3px 15px;cursor:pointer}
</style>
<script src="public/common/js/jquery.js"></script>
<script>
$(function(){
	tr_hover();
});
function tr_hover()
{
	$('.table tr').hover(function(){
		$(this).children('td').css('background','#ccffcc');
	},function(){
		$(this).children('td').css('background','white');
	});	
}
function get_children(obj,category_id)
{
	margin_left = $(obj).css('margin-left');
	margin_left_length = Number(margin_left.substr(0,margin_left.length-2)) + 10;
	if($(obj).parent().parent().next('tr').children('td').first().children('span').length > 0)
	{
		margin_left_next = $(obj).parent().parent().next('tr').children('td').first().children('span').css('margin-left');
		margin_left_next_length = Number(margin_left_next.substr(0,margin_left_next.length-2));
		if(margin_left_length == margin_left_next_length)
		{
			$(obj).parent().parent().nextAll('tr').each(function(){
				if($(this).children('td').first().children('span').css('margin-left') > String(margin_left_length-10)+'px')
				{
					$(this).remove();
				}else{
					return false;
				}
			});
			return;
		}
	}
	
	$.post('<?php echo site_url("admin/category/get_children")?>',{category_id:category_id},function(result){
		if(result == 0)
		{
			
		}else{
			result_obj = eval('('+result+')');
			result_obj_length = result_obj.length;
			html		= '';
			display		= '';
			url			= "<?php echo site_url('admin/category')?>";

			for(var i=0;i<result_obj_length;i++)
			{
				if(result_obj[i].category_display_top == '1')
				{
					display += '导航顶部显示';
				}
				if(result_obj[i].category_display_bottom == '1')
				{
					display += ' 导航底部显示';
				}
				html += "<tr><td><span class='explode' style='margin-left:"+margin_left_length+"px;' onclick='get_children(this,"+result_obj[i].category_id+")'><img src='public/admin/images/explode.gif'></span> "+result_obj[i].category_name+" <td><span style='color:#666666'>排序:</span> "+result_obj[i].category_sort+" </td><td><span style='color:#666666'>栏目id:</span> "+result_obj[i].category_id+" </td><td> <span style='color:#36F'>"+display+"</span></td><td align=right><a href='"+url+"/category_add/"+result_obj[i].category_id+"'>增加下级栏目</a> | <a href='"+url+"/category_edit/"+result_obj[i].category_id+"'>修改栏目</a> | <a href='"+url+"/category_move/"+result_obj[i].category_id+"'>移动栏目</a> | <a href='javascript:viod(0)' onclick='delete_category(this,"+result_obj[i].category_id+")'>删除栏目</a></td></tr>";				
			}
			$(obj).parent().parent().after(html);
			tr_hover();
		}
	});
}

function delete_category(obj,category_id)
{
	if(confirm('您确定要删除此栏目？删除此栏目将会把该分类下的所有文章或产品全部删除！谨慎操作！'))
	{
		$.post('<?php echo site_url("admin/category/delete_category")?>',{category_id:category_id},function(result){
			if(result == 1)
			{
				$(obj).parent().parent().remove();
			}else if(result == 2){
				alert('请先删除该栏目下的所有栏目！');
			}else{
				alert('删除失败！');
			}
		});
	}else{
		return false;
	}
	
}
</script>
</head>
<body>
	<div class="body">
    	<?php echo $this->position->get_position();?>
    	<div class="body_center">
            <table class="table">
				<tr><th colspan=5 style='font-weight:normal;'>请先添加顶级栏目,如果已经添加了栏目没显示请更新下栏目缓存</th></tr>
				<?php if($category):?>
					<?php foreach($category->result() as $value):?>
					<tr><td><span class='explode' style='margin-left:0px;' onclick='get_children(this,<?php echo $value->category_id?>)'><img src='public/admin/images/explode.gif'></span> <?php echo $value->category_name?> <td><span style='color:#666666'>排序:</span> <?php echo $value->category_sort?> </td><td><span style='color:#666666'>栏目id:</span> <?php echo $value->category_id?> </td><td> <span style='color:#36F'><?php if($value->category_display_top == '1'):?> 导航顶部显示 <?php endif;?><?php if($value->category_display_bottom == '1'):?> 导航底部显示 <?php endif;?></span></td><td align=right><a href="<?php echo site_url('admin/category/category_add/'.$value->category_id)?>">增加下级栏目</a> | <a href="<?php echo site_url('admin/category/category_edit/'.$value->category_id)?>">修改栏目</a> | <a href="<?php echo site_url('admin/category/category_move/'.$value->category_id)?>">移动栏目</a> | <a href='javascript:void(0)' onclick='delete_category(this,<?php echo $value->category_id?>)'>删除栏目</a></td></tr>
					<?php endforeach;?>
				<?php else:?>
					<tr><td colspan=5 class='center'>没有任何栏目，请先添加！</td></tr>
				<?php endif;?>	
			</table>
        </div>
    </div>
</body>
</html>